﻿Imports System.ServiceModel

Public Class Form1

    Private sync As System.Threading.SynchronizationContext

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        sync = Threading.SynchronizationContext.Current

        Dim del As New Action(AddressOf dowork)
        del.BeginInvoke(Nothing, Nothing)


    End Sub

    Public Sub dowork()
        Dim bs As New BasicHttpBinding
        Dim ea As New EndpointAddress("http://localhost:1053/WebSite1/Service.svc")
        Dim proxy = ChannelFactory(Of CustomProxy.ServiceProxy.IService).CreateChannel(bs, ea)
        Dim res = proxy.DoWork()
        Me.sync.Send(AddressOf updateui, res)

    End Sub
    Sub updateui(ByVal param As Object)
        Me.TextBox1.Text = param
    End Sub

End Class